package com.zzb.myshowme.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.zzb.myshowme.MyApplication;
import com.zzb.myshowme.R;
import com.zzb.myshowme.bean.UserInfo;
import com.zzb.myshowme.model.PhoneLoginModel;
import com.zzb.myshowme.utils.AccountUtils;
import com.zzb.myshowme.utils.CustomToast;
import com.zzb.myshowme.utils.HttpManager;
import com.zzb.myshowme.utils.SharedPreferencesUtil;
import com.zzb.myshowme.utils.UserInfoUtils;
import com.zzb.myshowme.wiget.ProgressDialogView;

import rx.Subscriber;

public class LogoActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logo);
        RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.rootLayout);
        AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
        animation.setDuration(1500);
        rootLayout.startAnimation(animation);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
//                getRegister();
                Intent intent = new Intent(LogoActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        }, 2000);
    }

    private void getRegister() {
        final String userId = AccountUtils.getUserId(this);
        final String passWord = AccountUtils.getPassword(MyApplication.getInstance());
//        Log.i("test", "userId = " + userId);
//        Log.i("test", "passWord = " + passWord);
        ProgressDialogView.Initial(this, "登录中..", true);
        if (!TextUtils.isEmpty(userId) && !TextUtils.isEmpty(passWord)) {
            ProgressDialogView.show();
//        HttpManager.getInstance().doHttpRequest(HttpManager.getInstance().getHttpService().loginReq(username, password), new Subscriber<ResponseBody>() {
            HttpManager.getInstance().doHttpRequest(HttpManager.getInstance().getHttpService().testReq(), new Subscriber<String>() {
                @Override
                public void onCompleted() {
                    Log.d("upload", "onCompleted down 成功======");

                }

                @Override
                public void onError(Throwable e) {
                    Log.d("down", "onError 上传头像======" + e.getMessage());
                    ProgressDialogView.dismiss();
                    CustomToast.show(LogoActivity.this, "网络连接失败，请查看网络设置", Toast.LENGTH_LONG);
                }

                @Override
                public void onNext(String string) {
                    ProgressDialogView.dismiss();
                    Intent intent = new Intent(LogoActivity.this, MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);//开新堆栈，并清空之前的堆栈
                    startActivity(intent);
                }
            });

        } else {
            //跳转到登录界面
            Intent intent = new Intent(LogoActivity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }
    }
}
